#from film_app.models import *

if not __name__ == '__main__':
    from .film_core import FilmSearch
    from film_app.models import *

else :

    from film_core import FilmSearch


class SaveInfoToDB():

    def save_film_info_brach(self, url):

        info = FilmSearch().get_film_info_brach(url)

        print(info)

        site_obj = SiteName.objects.get(pk = 1)

        film_name = info['name'].extend(info['bie_ming'])

        #film_name_list = [FilmName.objects.create(name = name) for name in film_name]

        director_list = [Director.objects.get_or_create(name = director)[0] for director in info['dao_yan']]
        
        actor_list = [Actor.objects.get_or_create(name = actor)[0] for actor in info['zhu_yan']]

        state_list = [State.objects.get_or_create(name = state)[0] for state in info['di_qu']]

        film_type_list = [FilmType.objects.get_or_create(film_type = lei_xing)[0] for lei_xing in info['lei_xing']]
        
        intor = info['jie_shao']

        Language = [Language.objects.get_or_create(Language = yu_yan)[0] for yu_yan in info['yu_yan']]

        film_objects = Film.objects.get_or_create(intor = intor)[0]

        #film_objects.site_name.add(site_obj)#如果是默认抛出关系表可用这种方法建立两个对象的关系

        #site_obj.film_set.add(film_objects)#如果是默认抛出关系表也可用这种方法建立两个对象的关系

        FilInSite.objects.create(film = film_objects, site_name = site_obj)#这里根据他们应该用这种方式来建立对象

        
        film_objects.director.add(*director_list)



if __name__ == '__main__':

    url = 'http://123ku.com/?m=vod-detail-id-14680.html'
    x = SaveInfoToDB()
    x.save_film_info_brach(url)

    '''
    {'show_url': [('https://www.697313.com:65/20190517/TylQLZs6/index.m3u8', 'HD高清'), ('https://www.697313.com:65/share/Rcxr2isvvXZ8Kuuy', 'HD高清')], 'img_url': ('https://img.sokoyo-rj.com/tuku/upload/vod/2019-05-17/201905171558030209.jpg', '阿波罗11号'), 'bie_ming': [''], 'dao_yan': ['托德·道格拉斯·米勒'], 'zhu_yan': ['巴兹
·奥德林', '琼·安·阿彻', '珍妮特·阿姆斯特朗', '尼尔·阿姆斯特朗', '约翰尼·卡森', '克利福德·E·查尔斯沃思
', '迈克尔·柯林斯', '迈克尔·柯林斯', '查尔斯·杜克', '吉因·克兰兹', '格林·伦尼', '理查德·尼克松', '理查
德·尼克松', 'Richard', 'Nixon', '迪克·斯雷顿', 'Deke', 'Slayton'], 'lei_xing': '综艺 ', 'yu_yan': ['英语'],
 'shang_yin': ['2019'], 'update': '2019-05-17 02:13', 'jie_shao': '\u3000这部93分钟的纪录片由Neon和CNN Film公
司出品，采用了首次发现的65毫米大画幅胶卷拍摄的影像资料和超过11,000小时的原始音频资料，为人类历史上最具标志性
和历史性的时刻展现全新的视角。 《阿波罗11号》用电影的方式讲述了这一航....', 'di_qu': ['美国'], 'name': ['阿波
罗11号']}
    '''
